package com.llb666.e.shop.infrastructure.persistence;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.llb666.e.shop.api.dto.OrderItemsCommentDto;
import com.llb666.e.shop.domain.entity.OrderItems;
import com.llb666.e.shop.domain.entity.bo.MyCommentBo;
import com.llb666.e.shop.domain.repository.ItemsCommentsRepository;
import com.llb666.e.shop.infracore.web.PagedGridResult;
import com.llb666.e.shop.infrastructure.mapper.ItemsCommentsMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 斌~
 * @date 2022/9/12 下午6:59
 */
@Repository
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class ItemsCommentsRepositoryImpl implements ItemsCommentsRepository {

    private final ItemsCommentsMapper itemsCommentsMapper;

    @Override
    public void saveComments(String userId, List<OrderItemsCommentDto> commentList) {
        Map<String, Object> map = new HashMap<>(2);
        map.put("userId", userId);
        map.put("commentList", commentList);
        itemsCommentsMapper.saveComments(map);
    }

    @Override
    public PagedGridResult<MyCommentBo> queryMyComments(String userId, Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        List<MyCommentBo> myCommentBos = itemsCommentsMapper.queryMyComments(userId);
        PageInfo<MyCommentBo> myCommentBoPageInfo = new PageInfo<>(myCommentBos);
        return PagedGridResult.setterPagedGrid(myCommentBoPageInfo);
    }
}
